package com.example.administrator.startproject419szy;


import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import com.example.administrator.startproject419szy.bean.WeatherInfo;
import com.example.administrator.startproject419szy.iface.WeatherListener;
import com.example.administrator.startproject419szy.model.Weather51Model;
import com.example.administrator.startproject419szy.model.WeatherModel;

public class MainActivity419 extends AppCompatActivity implements WeatherListener,View.OnClickListener{
    private EditText etcityno;
    private Button btnfind1;
    private Button btnfind2;
    private TextView tvcityname;
    private TextView cityNo;
    private TextView temp;
    private TextView WD;
    private TextView WS;
    private TextView SD;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main419);
        init();

    }

    private void init()
    {
        etcityno=(EditText)findViewById(R.id.editText);
        btnfind1=(Button)findViewById(R.id.button);
        btnfind2=(Button)findViewById(R.id.button2);
        tvcityname=(TextView)findViewById(R.id.textView);
//
        cityNo = (TextView) findViewById(R.id.bm);
        temp = (TextView) findViewById(R.id.wd);
        WD = (TextView) findViewById(R.id.fx);
        WS = (TextView) findViewById(R.id.fl);
        SD = (TextView) findViewById(R.id.sd);

  //
        btnfind1.setOnClickListener(this);
        btnfind2.setOnClickListener(this);
    }

    @Override
    public void onResponse(WeatherInfo weatherInfo) {
        if (weatherInfo!=null)
        {
            tvcityname.setText(weatherInfo.getCity());
            cityNo.setText(weatherInfo.getCityNo());
            temp.setText(weatherInfo.getTemp());
            WD.setText(weatherInfo.getWD());
            WS.setText(weatherInfo.getWS());
            SD.setText(weatherInfo.getSD());
        }
        else
        {
            tvcityname.setText("未知");
        }
    }

    @Override
    public void onFail(String msg) {
        tvcityname.setText(msg);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId())
        {
            case R.id.button:
                WeatherModel weatherModel=new WeatherModel();
                weatherModel.getWeather(etcityno.getText().toString(),this);
                break;
            case R.id.button2:
                Weather51Model weather51Model=new Weather51Model();
                weather51Model.getWeather(etcityno.getText().toString(),this);
                break;
            default:
                break;
        }
    }
}
